<?php

require_once('../../connection/_dbconnect_.php');
require_once('m_activity_log.php');

function getQshift($id){

	$fetchedQshift = array();
	
	$sql = "select idqueue_shift,description from queue_shift where idqueue_shift='".$id."'";
	
	$result = mysql_query($sql) or die("Query: $sql \n\n".mysql_error());
	while($obj = mysql_fetch_object($result)){
		$fetchedQshift[] = $obj->idqueue_shift;
		$fetchedQshift[] = $obj->description;
	}
	
	return $fetchedQshift;
}

function getQShifts(){	
	$parentArray = array();	
	$sql = "select idqueue_shift,description from queue_shift";
	
	$result = mysql_query($sql) or die("Query: $sql \n\n".mysql_error());
	while($obj = mysql_fetch_object($result)){
		$childArray = array();		
		$childArray[] = $obj->idqueue_shift;
		$childArray[] = $obj->description;		
		$parentArray[]= $childArray;
	}
	return $parentArray;
}

function addQshift($newQshift, $newDescription){
	
	$sql = "insert into queue_shift values ('".$newQshift."','".$newDescription."');";	

	$result = mysql_query($sql) or die("Query: $sql \n\n".mysql_error());
	
	if (!$result) {
		return false;
	} else {
		$date =new DateTime('NOW');		
		$result=addLogEntry($date->format('Y-m-d'), "Q-Shift=".$newQshift." was created");
		return true;
	}
}

function saveQshiftEdit($saveidqshift, $savedescription){	
	$sql = "update queue_shift set description='".$savedescription."' where idqueue_shift='".$saveidqshift."';";	
	$result = mysql_query($sql) or die("Query: $sql \n\n".mysql_error());
	
	if (!$result) {
		return false;
	} else {
		$date =new DateTime('NOW');		
		$result=addLogEntry($date->format('Y-m-d'), "Q-Shift=".$saveidqshift." was modified");
		return true;
	}
}

function deleteQShift($idqshift){
	
	$sql = "delete from queue_shift where idqueue_shift='".$idqshift."';";
	
	$result = mysql_query($sql);
	
	if (!$result) {
		return false;
	} else {
		$date =new DateTime('NOW');		
		$result=addLogEntry($date->format('Y-m-d'), "Q-Shift=".$saveidqshift." was deleted");
		return true;
	}
}

?>